package com.study.servlet.request;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
* @Name: GetRequestHeadInfo
* @Description: 使用Request对象获取http请求头信息
* @Author: 李超	lc_jack@foxmail.com
* @CreateDate: 2017-3-1 下午3:54:15 
* @Version: V1.0
 */
public class GetRequestHeadInfo extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		response.setContentType("text/html;charset=utf-8") ;
		PrintWriter out = response.getWriter() ;
		Enumeration<String> headerNames = request.getHeaderNames() ;
		while(headerNames.hasMoreElements()) {
			String headName = headerNames.nextElement() ;
			String headValue = request.getHeader(headName) ;
			out.print("<hr/>") ;
			out.print(headName + ": " + headValue) ;
			out.print("<br/>") ;
		}
		out.print("<hr/>") ;
		out.close() ;
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		this.doGet(request, response);
	}

}
